//
//  HWGameCommentSonProtocol.swift
//  HWanGame
//
//  Created by 王昌健 on 2022/3/24.
//  Copyright © 2022 94Wan. All rights reserved.
//

import UIKit

class HWGameCommentSonProtocol: NSObject {
    var models:[HWGameDetailCommentListModel]?
    var zanButtonClick:((_:String)->())?
    var replyContent:((_:HWGameDetailCommentListModel)->())?
    var videoPlayClick:((_:String)->())?
}

extension HWGameCommentSonProtocol:UITableViewDelegate,UITableViewDataSource {
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if indexPath.row == 0 {
            
        } else {
            replyContent?(models?[0].son_list[indexPath.row - 1] ?? HWGameDetailCommentListModel())
        }
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if (models?.count ?? 0) > 0 {
            if models![0].son_list.count > 0 {
                return models![0].son_list.count + 1
            } else {
                return 1
            }
        }else {
            return 0
        }
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let topCell = HWGameCommentSonTopCell.cellWithTableView(tableView: tableView)
        let cell = HWGameCommentSonCell.cellWithTableView(tableView: tableView)
        if indexPath.row == 0 {
            topCell.model = models?[0]
            topCell.zanButtonClick = {
                self.zanButtonClick?($0)
            }
            topCell.videoPlayClick = {
                self.videoPlayClick?($0)
            }
            return topCell
        }else {
            cell.model = models?[0].son_list[indexPath.row - 1]
            cell.zanButtonClick = {
                self.zanButtonClick?($0)
            }
            return cell
        }
    }
    
    
}
